package com.zmn.oms.business.impl.order;

import com.github.ltsopensource.core.json.JSON;
import com.zmn.base.price.common.dro.ratio.difficult.RatioDifficultDRO;
import com.zmn.base.price.dubbo.interfaces.ratio.difficult.RatioDifficultListRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.oms.business.interfaces.order.OrderExtendBService;
import com.zmn.oms.common.annotation.ZsNormalOrderWorkLog;
import com.zmn.oms.common.constant.OrderLogConsts;
import com.zmn.oms.model.dto.OrderExtendDTO;
import com.zmn.oms.model.entity.order.OrderExtend;
import com.zmn.oms.services.interfaces.order.OrderExtendService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @author sunlife
 * @date:2021/1/13 11:04 上午
 * description:
 */
@Slf4j
@Service
public class OrderExtendBServiceImpl implements OrderExtendBService {
    @Autowired
    OrderExtendService orderExtendService;
    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    RatioDifficultListRemoteService ratioDifficultListRemoteService;

    @Override
    @ZsNormalOrderWorkLog(type = OrderLogConsts.ORDER_LOG_TYPE_MODIFY_DIFFICULT_RATIO_ID, beforeProceed = false)
    public void modifyDifficultId(OrderExtendDTO orderExtendDTO) {
        Assert.notNull(orderExtendDTO.getOrderId(), "orderId不能为空");
        Assert.notNull(orderExtendDTO.getDifficultRatioId(), "难度系数Id不能为空");
        OrderExtend orderExtend = new OrderExtend();
        orderExtend.setExtId(orderExtendDTO.getOrderId());
        orderExtend.setDifficultRatioId(orderExtendDTO.getDifficultRatioId());

        // 组装日志需要的数据

        log.debug("获取难度系数信息入参：{}", orderExtendDTO.getDifficultRatioId());
        ResponseDTO<RatioDifficultDRO> responseDTO = ratioDifficultListRemoteService.getById(orderExtendDTO.getDifficultRatioId());
        log.debug("获取难度系数信息出参：{}", JSON.toJSONObject(responseDTO));
        if (responseDTO.isSuccess() && null != responseDTO.getData()) {
            orderExtendDTO.setDifficultRatio(responseDTO.getData().getRatio());
        }

        orderExtendService.updateOrderExtend(orderExtend);
    }
}
